package com.xiaoxing.zhinenghuacangku_jining.mvp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiaoxing.zhinenghuacangku_jining.R;
import com.xiaoxing.zhinenghuacangku_jining.mvp.ui.dbbase.QuedingMaterial;

import java.util.List;

public class JiNing_XianshiAdapter extends BaseAdapter {

    Context context;
    List<QuedingMaterial> list;
    LayoutInflater inflater;

    String wuliaoname="";
    String xiangmuname="";
    String shuliang="";
    public JiNing_XianshiAdapter(Context context, List<QuedingMaterial> list) {
        this.context = context;
        this.list = list;
        this.inflater=LayoutInflater.from(context);
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView=getInflater().inflate(R.layout.zhi_neng_cang_ku_ji_ning_xianshiitem,null);
            holder=new ViewHolder();
            holder.tv_xianshi=convertView.findViewById(R.id.tv_xianshi);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        if (list.get(position).getProjectName()!=null){
            xiangmuname=list.get(position).getProjectName();
        }
        if (list.get(position).getMaterialName()!=null){
            wuliaoname=list.get(position).getMaterialName();
        }
        if (list.get(position).getNum()!=null){
            shuliang=list.get(position).getNum();
        }
        holder.tv_xianshi.setText(xiangmuname+"-"+wuliaoname+"-"+shuliang);
        return convertView;
    }
    class ViewHolder{
        TextView tv_xianshi;
    }
    public void addAll(List<QuedingMaterial> xianshi){
        list.addAll(xianshi);
        notifyDataSetChanged();
    }
}
